import { useUserStore } from '@/stores/user.ts'

interface BarOptions {
	title : string,
	frontColor : string,
	backgroundColor : string,
}

export default function useTabbar() {
	const { isJob } = useUserStore()

	// 求职tabbar列表
	const jobTabBar = [
		{
			'index': 0,
			'text': '首页',
			'iconPath': '/static/images/tabbar/home.png',
			'selectedIconPath': '/static/images/tabbar/home-el.png'
		},
		{
			'index': 1,
			'text': '消息',
			'iconPath': '/static/images/tabbar/news.png',
			'selectedIconPath': '/static/images/tabbar/news-el.png'
		},
		{
			'index': 2,
			'text': '找工作',
			'iconPath': '/static/images/tabbar/office.png',
			'selectedIconPath': '/static/images/tabbar/office-el.png'
		},
		{
			'index': 3,
			'text': '我的',
			'iconPath': '/static/images/tabbar/mine.png',
			'selectedIconPath': '/static/images/tabbar/mine-el.png'
		}
	]

	// 招聘tabbar列表
	const hiringTabBar = [
		{
			'index': 0,
			'text': '推荐',
			'iconPath': '/static/images/tabbar/suggested.png',
			'selectedIconPath': '/static/images/tabbar/suggested-el.png'
		},
		{
			'index': 1,
			'text': '找人才',
			'iconPath': '/static/images/tabbar/talent.png',
			'selectedIconPath': '/static/images/tabbar/talent-el.png'
		},
		{
			'index': 2,
			'text': '简历',
			'iconPath': '/static/images/tabbar/resume.png',
			'selectedIconPath': '/static/images/tabbar/resume-el.png'
		},
		{
			'index': 3,
			'text': '个人',
			'iconPath': '/static/images/tabbar/mine.png',
			'selectedIconPath': '/static/images/tabbar/mine-el.png'
		}
	]

	const initTabBar = () => {
		const temps = isJob ? jobTabBar : hiringTabBar

		temps.forEach((each) => {
			uni.setTabBarItem(each)
		})
	}

	const setNavigationBar = (options : BarOptions = {
		title: '',
		frontColor: '#000000',
		backgroundColor: '#FFFFFF',
	}) => {
		uni.setNavigationBarTitle({
			title: options.title
		});

		uni.setNavigationBarColor({
			frontColor: options.frontColor,
			backgroundColor: options.backgroundColor,
			animation: {
				duration: 400,
				timingFunc: 'easeIn'
			}
		})
	}

	return {
		initTabBar,
		setNavigationBar,
	}
}